<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				initValue:{
					fileList:[]
				},
				productCache:"mkt-dd-salesOrderReview-title3-product-cache",
				subIndex:''
			})
		},
		methods:{
			initload(){
				let _that = this
				let pro1 = _that.om.request("tsysdict/getCombobox",{code:'38680'})
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title3","sourcePropertyId",'data',configSelectData(res[0],"id","dicname"))
					_that.$refs.autoform.initSelectIndex("title3","sourcePropertyId")
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.productCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.projectCode = d.projectCode
							let arr = [] 
							if(formdata.projectName){
								arr.push(formdata.projectName)
							}
							if(formdata.projectStd){
								arr.push(formdata.projectStd)
							}
							if(formdata.projectUnit){
								arr.push(formdata.projectUnit)
							}
							if(formdata.featureRemark){
								arr.push(formdata.featureRemark)
							}
							if(formdata.otherRemark){
								formdata.otherRemark = formdata.otherRemark + "," + arr.map(e => e).join("/")
							}else{
								formdata.otherRemark =  arr.map(e => e).join("/")
							}
							if(!(_that.subIndex + "")){
								formdata.projectName = d.projectName
								formdata.projectStd = d.projectStd
								formdata.projectUnit = d.projectUnit
								formdata.featureRemark = d.featureRemark
							}
							formdata.projectNum = d.rowNum
							formdata.featureRemark = d.featureRemark
							if(!_that.checkedit){
								formdata.projectDeliveryDate = d.projectDeliveryDate
							}
							_that.$refs.autoform.changeEditor("title3","projectName","type","labelbox")
							_that.$refs.autoform.changeEditor("title3","projectNeed","type","labelbox") 
							_that.$refs.autoform.changeEditor("title3","projectStd","type","labelbox") 
							_that.$refs.autoform.changeEditor("title3","projectUnit","type","labelbox") 
							_that.$refs.autoform.changeEditor("title3","featureRemark","type","labelbox") 
							uni.removeStorage({
								key:_that.productCache
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(e.index){
							_that.subIndex = Number(e.index)
						}
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("title3","projectId",{
								link:"../../public/pageSearch/pageSearch",
								"linkParam":{
									other:JSON.stringify({}),
									namefield:"projectCode",
									notefield:"projectName",
									extrafield:"projectMnemonic",
									cachename:_that.productCache,
									initload:true,
									searchfield:"q",
									url:"productShow/likeSerchPager",
								}
							},null,_that.autoformdata)
							if(e.index){
								if((_that.subIndex + 1) > Number(e.productListLength)){
									changeEditor(_that.autoformdata[0].editors,"projectName","type","textarea")
									changeEditor(_that.autoformdata[0].editors,"projectStd","type","textarea")
									changeEditor(_that.autoformdata[0].editors,"projectUnit","type","textarea")
									changeEditor(_that.autoformdata[0].editors,"projectNum","type","numberbox")
								}
							}else{
								changeEditor(_that.autoformdata[0].editors,"projectName","type","textarea")
								changeEditor(_that.autoformdata[0].editors,"projectStd","type","textarea")
								changeEditor(_that.autoformdata[0].editors,"projectUnit","type","textarea")
								changeEditor(_that.autoformdata[0].editors,"projectNum","type","numberbox")
							}
							
							changeEditor(_that.autoformdata[0].editors, "fileList", "fileUploadKey", "22")
							if(_that.formdata.fileList){
								var tempFileList = []
								var fileUrlList = _that.formdata.fileList.map(t=>{
									tempFileList.push(t.fileSaveName)
									return t.fileSaveName
								})
								changeEditor(_that.autoformdata[0].editors, "fileList", "fileUrlList", fileUrlList)
								changeEditor(_that.autoformdata[0].editors, "fileList", "tempFileList", tempFileList)
								}	
							 _that.initload()
							}
						}
					})
				}
							
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
